package com.yangzc.lion.common.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.yangzc.lion.common.dao.HQLInfo;
import com.yangzc.lion.common.dao.IBaseDao;
import com.yangzc.lion.common.model.IBaseModel;
import com.yangzc.lion.common.tag.Page;


public class BaseServiceImp<T extends IBaseModel> implements
		IBaseService<T, String> {
	private IBaseDao<T, String> baseDao;

	public String add(T modelObj) throws RuntimeException {
		return this.getBaseDao().add(modelObj);
	}

	public void delete(T modelObj) throws RuntimeException {
		this.getBaseDao().delete(modelObj);
	}

	public void flushHibernateSession() {
		this.getBaseDao().flushHibernateSession();
	}

	public void clearHibernateSession() {
		this.getBaseDao().clearHibernateSession();
	}

	public T findByPrimaryKey(Class<T> modelInfo, String id, boolean noLazy)
			throws RuntimeException {
		return this.getBaseDao().findByPrimaryKey(modelInfo, id, noLazy);
	}

	public T findByPrimaryKey(String id) throws RuntimeException {
		return this.getBaseDao().findByPrimaryKey(id);
	}

	public T findByPrimaryKey(String id, boolean noLazy)
			throws RuntimeException {
		return this.getBaseDao().findByPrimaryKey(id, noLazy);
	}

	public List<T> findByPrimaryKeys(String[] ids) throws RuntimeException {
		return this.getBaseDao().findByPrimaryKeys(ids);
	}

	public IBaseDao<T, String> getBaseDao() {
		return this.baseDao;
	}

	@Autowired
	public void setBaseDao(IBaseDao<T, String> baseDao) {
		this.baseDao = baseDao;
	}

	public List<T> find(String hql, Map<String, Object> param, Integer page,
			Integer pagesize) {
		return this.getBaseDao().find(hql, param, page, pagesize);
	}

	public List<T> find(String hql, Map<String, Object> param) {
		return this.getBaseDao().find(hql, param);
	}

	public List<T> find(String hql) {
		return this.getBaseDao().find(hql);
	}

	public Object findObject(String hql, Map<String, Object> param) {
		return this.getBaseDao().findObject(hql, param);
	}

	public Object findObject(String hql) {
		return this.getBaseDao().findObject(hql);
	}

	@Override
	public Object findObject(String hql, Map<String, Object> param,
			Integer firstResult, Integer rows) {
		return this.getBaseDao().findObject(hql, param, firstResult, rows);
	}

	@Override
	public List<?> findObjects(String hql, Map<String, Object> param,
			Integer firstResult, Integer rows) {
		return this.getBaseDao().findObjects(hql, param, firstResult, rows);
	}

	@Override
	public List<?> findObjects(String hql, Map<String, Object> param) {
		return this.getBaseDao().findObjects(hql, param);
	}

	@Override
	public List<?> findObjects(String hql) {
		return this.getBaseDao().findObjects(hql);
	}

	public Integer executeHql(String hql, Map<String, Object> param) {
		return this.getBaseDao().executeHql(hql, param);
	}

	public Integer executeHql(String hql) {
		return this.getBaseDao().executeHql(hql);
	}

	public void update(T modelObj) throws RuntimeException {
		this.getBaseDao().update(modelObj);
	}

	@Override
	public Page<T> findPage(HQLInfo hqlInfo) {
		return this.getBaseDao().findPage(hqlInfo);
	}

	@Override
	public Page<Map<String, Object>> findObjectPage(HQLInfo hqlInfo) {
		return this.getBaseDao().findObjectPage(hqlInfo);
	}
	
	public List findList(HQLInfo hqlInfo){
		return getBaseDao().findList(hqlInfo);
	}

	public List findList(String whereBlock, String orderBy){
		return getBaseDao().findList(whereBlock, orderBy);
	}

}
